package com.vhall.autotest.api_test.common;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketClient {

//  send  buf45 949
//	"GET /socket.io/?token=<token>&EIO=3&transport=websocket HTTP/1.1\r\n"
//	"Host: msg02.e.vhall.com:3000\r\n"
//	"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Fi"
//	"refox/41.0\r\n"
//	"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
//	"Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3\r\n"
//	"Accept-Encoding: gzip, deflate\r\n"
//	"Sec-WebSocket-Version: 13\r\n"
//	"Origin: http://e.vhall.com\r\n"
//	"Sec-WebSocket-Extensions: permessage-deflate\r\n"
//	"Sec-WebSocket-Key: AU3zEaMR7BN9UR+kbRyclQ==\r\n"
//	"Cookie: Hm_lvt_2d806e3142b873fd1741af629910957d=1446001098,1446014930,1446"
//	"026551,1446111609; Hm_lpvt_2d806e3142b873fd1741af629910957d=1446111609\r\n"
//	"Connection: keep-alive, Upgrade\r\n"
//	"Pragma: no-cache\r\n"
//	"Cache-Control: no-cache\r\n"
//	"Upgrade: websocket\r\n"
//	"\r\n"
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//    lrs_create_socket("socket34", "TCP", "RemoteHost=e.vhall.com:3000",  LrsLastArg);
//
//
//
//    lrs_send("socket34", "buf45", LrsLastArg);
//
//
//
//    lrs_receive("socket34", "buf46", LrsLastArg);
//
//
//	  lr_think_time(60);
  
	public static void main(String[] args) {
		Socket socket = null;
		try {
			socket = new Socket("msg02.t.vhall.com", 3000);
			OutputStream netOut = socket.getOutputStream();
			DataOutputStream doc = new DataOutputStream(netOut);
			BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			StringBuffer sb = new StringBuffer();
			sb.append(
					"GET /socket.io/?token=iOiJIUzI1NiJ9.eyJpZCI6IjMwNzE2IiwibmFtZSI6Ilx1NmUzOFx1NWJhMjQ3MjYwNjUzNSIsInJvb20iOiI2OTgwNTgwNjEiLCJyb2xlIjoidXNlciIsInVpZCI6bnVsbCwidHJhY2tJZCI6MTM0NDU1fQ.VGN-NKBa8q6Mg-BRZQLkbOCo_wWMVCChbmq3rhQPbm0&EIO=3&transport=websocket HTTP/1.1\r\n");
			sb.append("Host: msg02.t.vhall.com:3000\r\n");
			sb.append("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Fi");
			sb.append("refox/41.0\r\n");
			sb.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n");
			sb.append("Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3\r\n");
			sb.append("Accept-Encoding: gzip, deflate\r\n");
			sb.append("Sec-WebSocket-Version: 13\r\n");
			sb.append("Origin: http://t.vhall.com\r\n");
			sb.append("Sec-WebSocket-Extensions: permessage-deflate\r\n");
			sb.append("Sec-WebSocket-Key: AU3zEaMR7BN9UR+kbRyclQ==\r\n");
			sb.append("Cookie: Hm_lvt_2d806e3142b873fd1741af629910957d=1446001098,1446014930,1446");
			sb.append("026551,1446111609; Hm_lpvt_2d806e3142b873fd1741af629910957d=1446111609\r\n");
			sb.append("Connection: keep-alive, Upgrade\r\n");
			sb.append("Pragma: no-cache\r\n");
			sb.append("Cache-Control: no-cache\r\n");
			sb.append("Upgrade: websocket\r\n");
			sb.append("\r\n");
			doc.writeBytes(sb.toString());
			String line = null;
			while ((line = in.readLine()) != null) {
				System.out.println(line);
			}
			doc.close();
			in.close();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (socket != null) {
				try {
					socket.close();
				} catch (IOException e) {
				}
			}
		}
	}
}
